home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / NetObjects Fusion 9 Standard / NOF9_Full_EN.exe / data1.cab / FSI / lib / nof / AppComponent.js < prev    next >
Encoding:
JavaScript  |  2005-11-16  |  12.9 KB  |  332 lines

  1. /**
  2. * AppComponent
  3. */
  4.   function NOF_AppComponent(componentName, installFile) {
  5.     this.__proto__ = NOF_AppComponent.prototype;
  6.  
  7.     this.componentName = componentName;
  8.     this.installFile = installFile;        
  9.     
  10.     this.application = null;
  11.     
  12.     this.comp = NOF.App.getFSIApp().GetCurrentComponent();
  13.     
  14.     //return this;
  15.   }
  16.   
  17.   //function NOF_AppComponent_ProtoBuilder() 
  18.   {
  19.     
  20.     var method = NOF_AppComponent.prototype;
  21.     method.CLASS_NAME             = "NOF.AppComponent";        
  22.       
  23.     method.CONFIG_DIALOG_PATH     = "Configure.html";
  24.     method.COMPONENT_CLASS        = null;
  25.     
  26.     method.MAX_INSTANCES_IN_PAGE        = -1;
  27.     method.MAX_SAME_CLASS_INSTANCES    = -1;
  28.     
  29.     method.MAX_INSTANCES_EXCEEDED        = "MAX_INSTANCES_EXCEEDED";
  30.     method.MAX_CLASS_INSTANCES_EXCEEDED= "MAX_CLASS_INSTANCES_EXCEEDED";
  31.     //these constants can be moved outside this class
  32.     method.POST_FORM_METHOD    = "POST";
  33.     method.GET_FORM_METHOD        = "GET";
  34.  
  35.     //Width of the component in Page view.
  36.     method.setWidth        = function (width) { this.comp.Width = width; }
  37.     method.getWidth        = function () { return this.comp.Width; }
  38.     //Height of the component in Page view.
  39.     method.setHeight        = function (height) { this.comp.Height = height; }
  40.     method.getHeight        = function () { return this.comp.Height; }
  41.     
  42.     method.setOutputCode        = function (code) { this.comp.SetHTML(code); }
  43.     method.setHeaderScript        = function (pId, code) { this.comp.SetHeaderScript(p,Id, code); }
  44.     method.setBodyEventHandler    = function (pId, pHandler) { this.comp.SetBodyEventHandler(p,Id, pHandler); }
  45.     method.addFile                = function (filePath, pNumber) { this.comp.AddFile(filePath, pNumber); }
  46.     method.removeFile            = function (pNumber) { this.comp.RemoveFile(pNumber); }
  47.     method.setPreviewHTML        = function (pHTML) { this.comp.SetPreviewHTML(pHTML); }
  48.     method.getNode                = function () { return this.comp.GetNode(); }
  49.     method.getBackgroundColor    = function () { return this.comp.GetBackgroundColor(); }
  50.     
  51.     method.setIsFullyConfigured= function (configured) { this.comp.Initialized = configured; }
  52.     method.isFullyConfigured    = function () { return this.comp.Initialized; }
  53.     
  54.     method.setComponentClass    = function (className) { this.comp.Class = className; }
  55.     method.getComponentClass    = function () { return this.comp.Class; }
  56.  
  57.     method.setComponentName    = function (compName) { this.comp.Name = this.componentName = compName; }
  58.     method.getComponentName    = function () { return this.comp.Name; }
  59.     
  60.  
  61.     method.setRequiresUpdate    = function (require) { this.comp.RequiresUpdate = require; }
  62.     method.requiresUpdate        = function () { return this.comp.RequiresUpdate; }
  63.     
  64.     method.getApplication        = function () {return this.application}
  65.     method.setApplication        = function (app) {return (this.application = app); }
  66.   
  67.     //abstract, should be implemented in subclasses
  68.     method.handleExceedInstancesLimit        = function () {}
  69.     
  70.     method.setIsFormElement    = function (isFormElem) { this.comp.IsFormElement = isFormElem;    }        
  71.     method.isFormElement        = function () { return this.comp.IsFormElement; }
  72.     
  73.     method.isControlingFormAction        = function () { return this.comp.ControlsFormAction; }
  74.     method.setIsControlingFormAction    = function (controlsAction) { this.comp.ControlsFormAction = controlsAction; }
  75.     // call setIsControlingFormAction(true) before setFormAction
  76.     method.setFormAction        = function (formAction) { this.comp.FormAction = formAction; }
  77.     method.getFormAction        = function () { return this.comp.FormAction; }
  78.     
  79.     method.isControlingFormMethod        = function () { return this.comp.ControlsFormMethod; }
  80.     method.setIsControlingFormMethod    = function (controlsMethod) { this.comp.ControlsFormMethod = controlsMethod; }
  81.     // call setIsControlingFormMethod(true) before setFormMethod
  82.     method.setFormMethod        = function (formMethod) { this.comp.FormMethodIsPost = (formMethod == this.POST_FORM_METHOD); }
  83.     method.getFormMethod        = function () { return (this.comp.FormMethodIsPost) ? this.POST_FORM_METHOD : this.GET_FORM_METHOD; }
  84.  
  85.     method.isControlingFormEncoding    = function () { return this.comp.ControlsFormEncoding; }
  86.     method.setIsControlingFormEncoding    = function (controlsEncoding) { this.comp.ControlsFormEncoding = controlsEncoding; }
  87.     // call setIsControlingFormEncoding(true) before setFormEncoding
  88.     method.setFormEncoding        = function (formEncoding) { this.comp.FormEncoding = formEncoding; }
  89.     method.getFormEncoding        = function () { return this.comp.FormEncoding; }
  90.     
  91.     method.initialize = function () {
  92.       var METHOD_NAME = "initialize";
  93.       //cfgLogger.info("init NOF.AppComponent", "NOF.AppComponent", METHOD_NAME);
  94.       //cfgLogger.info("set Name="+this.componentName+", location="+this.INSTALL_PATH, "NOF.AppComponent", METHOD_NAME);
  95.       //this.comp.Name = this.componentName;            
  96.       this.setComponentName(this.componentName);
  97.       
  98.       this.comp.Location = this.INSTALL_PATH + this.installFile; //+ this.componentName;
  99.       if (this.COMPONENT_CLASS != null) {
  100.         this.setComponentClass(this.COMPONENT_CLASS);
  101.       }
  102.       
  103.       if ( this.MAX_INSTANCES_IN_PAGE > 0 ) {
  104.         if ( this.exceedMaxInstancesInPage() ) {
  105.           //try {
  106.             //abstract method
  107.             this.handleExceedInstancesLimit( this.MAX_INSTANCES_EXCEEDED );
  108.           //} catch(excd) {
  109.           //    //cfgLogger.warn("AppComponent.initialize got "+excd);
  110.           //    return;
  111.           //}
  112.         }
  113.       }
  114.       
  115.       if ( (this.COMPONENT_CLASS != null) && (this.MAX_SAME_CLASS_INSTANCES > 0) ) {
  116.         if ( this.exceedMaxClassInstancesInPage() ) {
  117.           //try {
  118.             //abstract method
  119.             this.handleExceedInstancesLimit( this.MAX_CLASS_INSTANCES_EXCEEDED );
  120.           //} catch(excd) {
  121.           //    //cfgLogger.warn("AppComponent.initialize got "+excd);
  122.           //    return;
  123.           //}
  124.         }                
  125.       }
  126.       
  127.       var appName = this.getApplication().getName();
  128.       //cfgLogger.info("set appName="+appName, "NOF.AppComponent", METHOD_NAME);
  129.       this.comp.Method    = appName + ".dispatchEvent('ComponentMethod')";
  130.       this.comp.OnCopy    = appName + ".dispatchEvent('ComponentCopy')";
  131.       this.comp.OnLoad    = appName + ".dispatchEvent('ComponentLoad')";
  132.       this.comp.OnDelete    = appName + ".dispatchEvent('ComponentDelete')";
  133.       //cfgLogger.info("all component's events set", "NOF.AppComponent", METHOD_NAME); 
  134.       
  135.       this.setPlaceholderImage(this.placeholderImage);                        
  136.       
  137.       //cfgLogger.info("end", "NOF.AppComponent", METHOD_NAME);
  138.     }
  139.     
  140.     /**
  141.     * method getProperty
  142.     */
  143.     method.getProperty = function (key) {
  144.       return (this.comp != null) ? this.comp.GetVar(key) : null;    
  145.     }
  146.     
  147.     /**
  148.     * method setProperty
  149.     */
  150.     method.setProperty = function (key, value) {
  151.       if (this.comp != null) {
  152.         this.comp.SetVar(key, value);
  153.       }
  154.     }
  155.     
  156.     
  157.     /** 
  158.     * method onComponentMethod
  159.     */          
  160.     method.onComponentMethod = function () {        
  161.       var METHOD_NAME = "onComponentMethod";
  162.       
  163.       //cfgLogger.info("init ", "NOF.AppComponent", METHOD_NAME);
  164.       try {
  165.         var params = [ NOF, this.getApplication().getMainWindow(), this, eval(this.CLASS_NAME+"ConfigureDialog")];
  166.         if ( this.NAMESPACE ) {
  167.           params[params.length] = eval(this.NAMESPACE);
  168.         }
  169.         var configResult = window.showModalDialog(this.CONFIG_DIALOG_PATH, params, "status:no;help:no;border:thin;dialogWidth:400px;dialogHeight:430px;center:yes;scroll:no;");
  170.         //cfgLogger.info("end with " + configResult, "NOF.AppComponent", METHOD_NAME);                
  171.         return configResult;
  172.         
  173.       } catch(err) {
  174.         //cfgLogger.warning("ERROR", "NOF.AppComponent", METHOD_NAME, [err]);
  175.       }
  176.     }
  177.     
  178.     /** 
  179.     * method onComponentLoad
  180.     */          
  181.     method.onComponentLoad = function () {        
  182.       var METHOD_NAME = "onComponentLoad";
  183.       //cfgLogger.info(" init ", "NOF.AppComponent", METHOD_NAME);
  184.     }
  185.     /** 
  186.     * method onComponentCopy
  187.     */          
  188.     method.onComponentCopy = function() {        
  189.       var METHOD_NAME = "onComponentCopy";
  190.       //cfgLogger.info(" init ", "NOF.AppComponent", METHOD_NAME);
  191.     }
  192.     /** 
  193.     * method onComponentDelete
  194.     */          
  195.     method.onComponentDelete = function () {        
  196.       var METHOD_NAME = "onComponentDelete";
  197.       //cfgLogger.info(" init ", "NOF.AppComponent", METHOD_NAME);
  198.     }        
  199.     
  200.     
  201.     /** 
  202.     * method setPlaceholderImage
  203.     */          
  204.     method.setPlaceholderImage = function (imgPath) {    
  205.       var METHOD_NAME = "setPlaceholderImage";
  206.       //cfgLogger.info(" imgPath="+imgPath, "NOF.AppComponent", METHOD_NAME);
  207.       
  208.       this.placeholderImage = imgPath;
  209.       this.comp.SetPlaceholderImage(this.INSTALL_PATH + this.placeholderImage);
  210.     }    
  211.     
  212.     /** 
  213.     * method exceedMaxInstancesInPage
  214.     */          
  215.     method.exceedMaxInstancesInPage = function () {        
  216.       var METHOD_NAME = "exceedMaxInstancesInPage";
  217.       //cfgLogger.info("init", "NOF.AppComponent", METHOD_NAME);      
  218.       if ( this.MAX_INSTANCES_IN_PAGE <= 0 )
  219.         return false;
  220.       //var cIter = app2.GetComponentsOfClass( this.COMPONENT_CLASS );
  221.       var cIter = this.getApplication().getFSIApp2().GetComponentsWithName( this.componentName );
  222.       
  223.       var no = cIter.count();
  224.       var j = 0;
  225.       var currentNode = this.getNode();
  226.       for (var i=0; i < no; i++) {
  227.         if ( currentNode.Number == cIter.GetNext().GetNode().Number )
  228.           j++;
  229.       }
  230.       //cfgLogger.info(" no=" + no +" in current page = "+j, "NOF.AppComponent", METHOD_NAME);                       
  231.       //cfgLogger.info("end. returns " + ( j > this.MAX_INSTANCES_IN_PAGE ), "NOF.AppComponent", METHOD_NAME);
  232.       return ( j > this.MAX_INSTANCES_IN_PAGE );
  233.     }    
  234.     
  235.     /** 
  236.     * method exceedMaxClassInstancesInPage
  237.     */          
  238.     method.exceedMaxClassInstancesInPage = function () {        
  239.       var METHOD_NAME = "exceedMaxClassInstancesInPage";
  240.       //cfgLogger.info("init", "NOF.AppComponent", METHOD_NAME);
  241.       //var app2 = new ActiveX("FSI.FSIApplication2");
  242.       if ( (this.MAX_SAME_CLASS_INSTANCES <= 0) || (this.COMPONENT_CLASS == null) )
  243.         return false;
  244.       //var cIter = app2.GetComponentsOfClass( this.COMPONENT_CLASS );
  245.       var cIter = this.getApplication().getFSIApp2().GetComponentsOfClass( this.COMPONENT_CLASS );
  246.       //GetComponentsWithName(String pName)
  247.       var no = cIter.count();
  248.       var j = 0;
  249.       var currentNode = this.getNode();
  250.       for (var i=0; i < no; i++) {
  251.         var pId = cIter.GetNext().GetNode().Number;
  252.         //cfgLogger.info(" "+currentNode.Number+" = "+pId, "NOF.AppComponent", METHOD_NAME);
  253.         if ( currentNode.Number == pId )
  254.           j++;
  255.       }            
  256.       //cfgLogger.info(" no=" + no +" in current page = "+j, "NOF.AppComponent", METHOD_NAME);                 
  257.       //app2 = null;
  258.       //cfgLogger.info("end. returns " + ( j > this.MAX_SAME_CLASS_INSTANCES ), "NOF.AppComponent", METHOD_NAME);
  259.       return ( j > this.MAX_SAME_CLASS_INSTANCES );
  260.     }
  261.     
  262.     
  263.     /*
  264.     * getAllComponents
  265.     */
  266.     method.getAllComponents = function () {
  267.       var cmps = new Array();
  268.       var cIter = null;
  269.       if (arguments.length == 0) {
  270.         cIter = this.getApplication().getFSIApp().GetAllComponents();
  271.       } else if( arguments[0].toLowerCase() == "name" ) {
  272.         cIter = this.getApplication().getFSIApp2().GetComponentsWithName(arguments[1]);
  273.       } else if( arguments[0].toLowerCase() == "class" ) {
  274.         cIter = this.getApplication().getFSIApp2().GetComponentsOfClass(arguments[1]);
  275.       } else {
  276.         return null;
  277.       }
  278.       var no = cIter.count();
  279.       var cmp = null;
  280.       var j = 0;
  281.       for (var i=0; i < no; i++) {
  282.         cmp = cIter.GetNext();                
  283.         try {    
  284.           j = cmps.length;
  285.           eval("cmps[j] = new "+ cmp.Name +"()");
  286.           cmps[j].comp = cmp;
  287.         } catch(e) {
  288.           //cfgLogger.warning("ERROR", "NOF.AppComponent", METHOD_NAME, [e]);    
  289.         }                
  290.       }
  291.       return cmps;
  292.     }
  293.     
  294.     /**
  295.     * getComponentsWithName(String pName)
  296.     **/
  297.     method.getComponentsWithName = function (cName) {
  298.       return this.getAllComponents("name", cName);
  299.     }
  300.  
  301.     /**
  302.     * getComponentsOfClass(String cClass)
  303.     **/        
  304.     method.getComponentsOfClass = function (cClass) {
  305.       return this.getAllComponents("class", cClass);
  306.     }
  307.   }
  308.   
  309.   
  310.   //NOF_AppComponent_ProtoBuilder();    
  311.   NOF.__proto__.AppComponent = NOF_AppComponent;
  312.  
  313.   
  314.   
  315.   
  316.   /*
  317.   function runComponent(compName) {
  318.     //cfgLogger.info("runComponent init, " + compName);
  319.     var cmp = null;
  320.     try {
  321.       cmp = eval("new "+ compName + "()");
  322.       cmp.initialize();
  323.       //cmp.properties();
  324.       //cmp.comp.Initialized = true;
  325.     } catch(e) {
  326.       alert(e.description);
  327.       //cfgLogger.info("runComponent " + e.description);
  328.     }
  329.     //cfgLogger.info("runComponent end");
  330.     return cmp;
  331.   }
  332.   */